package Server.Agent;

import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.json.JSONObject;
import network.handler.NetHandlerMgr;
import Server.Model.Base.SHMUser;
import Server.Model.Hall.dthall;
import msg.protocal.CMD_enum;
import msg.protocal.DataWrapper;
import msg.protocal.ObjectWrapper;

public class GameDB {
	public GameDB() {
	}
	public void push_task(GameAgent agent, JSONObject root) {
		String command = root.getString("command");
		DataWrapper data = new DataWrapper(CMD_enum.DB_SAVETO_MYSQL,command);
		data._origAgent = agent;
		data._origJson = root;
		data._attachOp = "";
		NetHandlerMgr.getInstance().pushDbTask(data);
	}
	public void push_task(GameAgent agent,org.json.JSONObject root) {
		String command = root.getString("command");
		DataWrapper data = new DataWrapper(CMD_enum.DB_SAVETO_MYSQL,command);
		data._origAgent = agent;
		data._origJson = JSONObject.fromObject(root.toString());
		data._attachOp = "";
		NetHandlerMgr.getInstance().pushDbTask(data);
	}
	static public GameDB __db = new GameDB();

	public static final GameDB getInstance() {
		return __db;
	}
}

class CMD_LoginSuccess {
	SHMUser m_objUser;
	String userIcon;
	void setUser(SHMUser data) {
		m_objUser = data;
	}

	String getJsonData() {
		String strObjUser = m_objUser.getJsonData();
		JSONObject objUser = JSONObject.fromObject(strObjUser);
		JSONObject root = new JSONObject();
		root.put("command", "hall_login");
		root.put("m_objUser", objUser);
		root.put("sUserIcon", userIcon);
		return root.toString();
	}
};

class CMD_WXLoginSuccess {
	SHMUser m_objUser;
	String userIcon;
	void setUser(SHMUser data) {
		m_objUser = data;
	}

	String getJsonData() {
		String strObjUser = m_objUser.getJsonData();
		JSONObject objUser = JSONObject.fromObject(strObjUser);
		JSONObject root = new JSONObject();
		root.put("command", "hall_wxlogin");
		root.put("m_objUser", objUser);
		root.put("sUserIcon", userIcon);
		return root.toString();
	}
};